<?php

    // Include domain-specific classes
    require dirname(__FILE__) . DIRECTORY_SEPARATOR . '_include.php';
    
    try {
        
        //----------------------------------------------------------------------
        // Initialise domain objects
        
        // The Master Datagateway will be the base object to amend functionality.
        
        $obj_datagateway = new DataGateway_Master();
        
        // The Environment object will store the temporary environment details,
        // and then be weaved around the particular method
        
        $obj_environment = new ClassStructure_Mixin_PhpEnvironment();
    
        $obj_environment->defineEnvironment(array(
            ClassStructure_Mixin_PhpEnvironment::MEMORY_LIMIT => '500M',
            ClassStructure_Mixin_PhpEnvironment::MAX_EXECUTION_TIME => 0
        ));
        
        
        //----------------------------------------------------------------------
        // Create weaved delegator
        
        // Encapsulate the base object within a Weaved Delegator; this will 
        // provide the means to add functionality around a method.
        
        $obj = new ClassStructure_Weaved_Delegator($obj_datagateway);
        
        $obj->__weaveAdviceBefore(
            array($obj_environment, 'setupEnvironment'), 
            'insertPressTitle'
        );
        $obj->__weaveAdviceAfter(
            array($obj_environment, 'revertEnvironment'), 
            'insertPressTitle'
        );
        
        
        //----------------------------------------------------------------------
        // Test functionality
        
        $obj->insertPressTitle(array(
            'title_name' => 'Financial Times',
            'title_slug' => 'financial-times',
            'title_type' => 1,
            'categories' => array(1)
        ));
        
        echo "\n\n";
        
        //----------------------------------------------------------------------
        // Expose structure
        
        echo ClassStructure_UtilityFunctions::getObjectSignature($obj);
        echo "\n";
        echo ClassStructure_UtilityFunctions::getAdviceSignature($obj, 'insertPressTitle');
        
    } catch (Exception $obj_exception) {
        print_r($obj_exception);
    }
